Skip to content

perf(roadmap): share the listing snapshot and facts in Valkey - #6583

Merged
dan-petty merged 20 commits into
mainfrom
perf/4668-share-the-listing-snapshot-in-valkey
Nov 21, 2026
Merged

dan-petty merged 20 commits into
mainfrom
perf/4668-share-the-listing-snapshot-in-valkey

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Share the listing snapshot of each public repository and the PyPI and
deps.dev facts in valkey-devops, behind the breaker of the cache tier
(ADR 0023 section 2). A process with no local snapshot starts from the
shared copy and reads only the changes. A save of unchanged records
writes none. While Valkey is down, each process uses its local tiers.

Memory bound: --maxmemory 256mb in a 384Mi limit (two thirds).
Shared load of the devops-cli snapshot (6,571 records, 15.7 MB) on a
temporary pod: median 1.89 s, max 2.61 s, budget 20 s.

Live checks after the release: the Deployment runs --maxmemory 256mb
and 384Mi, and redis_config_maxmemory{job="valkey-devops"} is
268435456. Drill: valkey-devops at 0 replicas for 10 minutes; no job
fails, and devops_cli_brain_reads_total{result="fallback"} rises.

See #4624, #4704.

Closes #4668

Change: openspec/changes/archive/2026-11-21-4668-share-the-listing-snapshot-in-valkey/

…lkey

Plan #4668 as the OpenSpec change 4668-share-the-listing-snapshot-in-valkey.
The memory bound of valkey-devops is --maxmemory 256mb inside a 384Mi limit.
The bound has a validator command and a live check as its proof, and no test.
ADR 0023 does not change: its line already names 256 MB.
The four scenarios watch_lost, hscan_bytes, rename_hash_ttl and
expire_hdel_unlink, and binary words and replies in the replay record.
They fail until a real valkey-server records them.

Failed tests:
- tests/valkey/test_valkey_contract.py::test_the_record_is_of_the_locked_valkey_py
- tests/valkey/test_valkey_contract.py::test_the_fake_answers_each_scenario_as_the_recorded_server[watch_lost]
- tests/valkey/test_valkey_contract.py::test_the_fake_answers_each_scenario_as_the_recorded_server[hscan_bytes]
- tests/valkey/test_valkey_contract.py::test_the_fake_answers_each_scenario_as_the_recorded_server[rename_hash_ttl]
- tests/valkey/test_valkey_contract.py::test_the_fake_answers_each_scenario_as_the_recorded_server[expire_hdel_unlink]
The tier keeps a binary hash with a TTL, a lost WATCH transaction
writes nothing, a failed command counts its command and error, and a
silent Valkey host opens the breaker after one timeout (T3). The
fixtures shared_valkey and silent_valkey come with them.

Failed tests:
- tests/valkey/test_valkey_cache_tier.py::test_the_cache_tier_keeps_a_binary_hash_with_a_ttl
- tests/valkey/test_valkey_cache_tier.py::test_a_writer_whose_watched_key_changed_writes_nothing
- tests/valkey/test_valkey_cache_tier.py::test_a_failed_tier_command_counts_its_command_and_error
- tests/valkey/test_valkey_cache_tier.py::test_a_silent_valkey_times_out_and_opens_the_breaker
ValkeyClient and ValkeyCacheTier get HGET, HSET, HDEL, HSCAN, EXPIRE,
UNLINK, RENAME and one WATCH transaction that is not tried again. A
read of a hash value uses NEVER_DECODE, so a zlib value comes back as
bytes. Each failed or unsent command of the tier adds one to
devops_cli_valkey_cache_errors_total. The four counters of the project
brain and their label values are declared.
A shared read fills the in-process tier (T1), a down shared tier gives
the source value and keeps the write in memory (T2), a value over 1 MiB
stays in memory and each key has a TTL (T5), a value of an old kind or
schema is read from the source (T6), and the counters send only fixed
labels.

Failed tests:
- tests/valkey/test_tiered.py::test_a_shared_read_fills_the_memory_tier
- tests/valkey/test_tiered.py::test_a_down_shared_tier_gives_the_source_value_and_keeps_the_write_in_memory
- tests/valkey/test_tiered.py::test_an_oversize_value_stays_in_memory_and_each_key_has_a_ttl
- tests/valkey/test_tiered.py::test_a_value_of_an_old_kind_or_schema_is_read_from_the_source
- tests/valkey/test_tiered.py::test_the_brain_counters_send_only_fixed_labels
TieredMapping is a MutableMapping over an in-process TTLCache and the
cache tier of the process, so cachetools.cached takes it as its cache.
A shared hit fills the memory tier; a value with another schema key is
a miss; a value over 1 MiB stays in memory; each key gets the TTL of
the mapping. Each read and write adds one to the brain counters.
A cold process reads the shared snapshot and one page of changes, the
newer of the two copies gives the watermark, a round with the shared
tier down reads the local file (T2), a trial after the cooldown and a
lost WATCH transaction (T4), an older watermark and a full read, no key
of a private repository, no visibility read without the shared tier,
and a shared load past its budget.

Failed tests:
- tests/roadmap/stores/test_listing_shared.py::test_a_cold_process_reads_the_shared_snapshot_and_at_most_two_pages
- tests/roadmap/stores/test_listing_shared.py::test_the_newer_copy_of_the_two_tiers_gives_the_watermark
- tests/roadmap/stores/test_listing_shared.py::test_a_round_with_the_shared_tier_down_reads_the_local_file
- tests/roadmap/stores/test_listing_shared.py::test_a_trial_after_the_cooldown_lets_the_newer_snapshot_replace_the_older
- tests/roadmap/stores/test_listing_shared.py::test_an_older_writer_loses_its_watch_transaction
- tests/roadmap/stores/test_listing_shared.py::test_an_older_watermark_does_not_replace_the_shared_snapshot
- tests/roadmap/stores/test_listing_shared.py::test_a_full_read_replaces_the_shared_snapshot_whole
- tests/roadmap/stores/test_listing_shared.py::test_no_key_of_a_private_repository_is_written
- tests/roadmap/stores/test_listing_shared.py::test_no_visibility_read_without_the_shared_tier
- tests/roadmap/stores/test_listing_shared.py::test_a_shared_load_past_its_budget_falls_back
ValkeySnapshotStore keeps the snapshot of a repository in one hash of
zlib JSON records with a meta field and a TTL of 7 days. A writer
writes only when its watermark is not older, in one WATCH transaction
that is not tried again; a full read replaces the hash through a
temporary key and RENAME. TieredSnapshotStore loads the local and the
shared copy and takes the fit copy with the newer watermark, saves the
shared copy first, and holds no key of a private repository: it reads
the visibility only after Valkey answered, and a failed read counts as
private. intake_listing and lane_listing give it to every caller.
A second PyPI read of one package in another spelling and a second
deps.dev read of one project, each with an empty memory tier, send no
request. A failed PyPI read keeps nothing; it passes on the base and
guards the change.

Failed tests:
- tests/roadmap/test_roadmap_alternatives.py::test_a_second_pypi_read_of_one_package_sends_no_request
- tests/roadmap/test_roadmap_alternatives_project_facts.py::test_a_second_deps_dev_read_of_one_project_sends_no_request
_read_pypi and _linked_packages go through cachetools.cached over one
TieredMapping each, under valkey:brain:v1:fact:pypi with the canonical
package name and valkey:brain:v1:fact:deps-dev with the project key in
lower case, for 24 hours. A package or project that a process or
another pod read sends no request; a failed read keeps nothing.
The listing snapshots of the public repositories (about 15 MB) and the
tool facts join the embeddings and the threat-intelligence reads. At
96 MiB the old pod evicted 3,600 keys in 7 days. 256 MiB is two thirds
of the 384Mi limit, so the three-quarters rule of the llm Valkeys
holds, and so does decision 6 of #4624.
k8s/README.md gives valkey-devops its new keys, its bound of 256 MiB in
384Mi and no key of a private repository until #4704. The intake page
names the shared copy of the listing snapshot, the alternatives page
the fact cache of PyPI and deps.dev, and the telemetry page the four
new counters.
A temporary pod of valkey/valkey:9.1.4-alpine, the image of
valkey-devops, recorded the replies of watch_lost, hscan_bytes,
rename_hash_ttl and expire_hdel_unlink. The records of the earlier
scenarios did not change. The same pod measured the shared load of the
devops-cli snapshot: 6,571 records, 15.7 MB in Valkey, five cold loads
with a median of 1.89 s and a maximum of 2.61 s. The pod is deleted.
The test-tree row refused the registry of the tiered mappings as a
container that the floor does not reset. reset_tiered_mappings now
starts a new generation, and a mapping empties its memory tier at its
next access. The proposal gives the measured load in place of the
path of the script.
T3 now reads two facts through cachetools.cached over a TieredMapping:
each read gives the source value, the first Valkey read counts a
timeout, and no later command opens a second connection.
… and counts

A save of the records that the shared copy holds writes no record. A new
meta of the same records during a load keeps the shared copy. A time with
no UTC offset or a record past 1 MiB is a miss. A repository that became
private leaves the shared tier. One key holds each spelling of a name. A
load from the local file counts local. A lost connection in a WATCH
transaction opens the breaker. The Valkey fake runs a test action after
each command, in place of test subclasses of the cache tier.
The meta of the shared snapshot holds a digest of its records in place of
a token that each save made new. A save of the records that the shared
copy holds sends only EXPIRE and counts unchanged; a save of known records
sends only the changes. A load uses the records only when they have the
digest of meta, so a new meta of the same records does not spoil a scan.

The values of the shared tier are untrusted: a time with no UTC offset and
a record that expands past 1 MiB make the copy a miss. The key and the
visibility answers use RepoRef.key. A round removes the key of a
repository that became private and counts removed. A load from the local
file counts local. A lost connection in a WATCH transaction raises its
connection error, so the breaker opens.

The roadmap-intake-listing spec gets a MODIFIED delta for the full read
and the reads of the Service through the shared tier.
Lane A of a process saves a newer watermark. Lane B, whose local copy is
older, takes the records that the store of the process holds, and sends
no HSCAN.
In a busy repository the watermark moves on each round, so the local copy
of each lane is older than the shared copy that the last lane wrote, and
each lane round scanned the 14 MB of devops-cli again behind the lock of
the breaker. The shared store of the process keeps the records of the
last copy that it wrote or read, and a load whose meta names them sends
no HSCAN.
@dan-petty dan-petty added type/infra Type infra: the build, CI, images or cluster scope/roadmap The roadmap jobs: intake, refine, stage, implement and the Service that runs them labels Nov 21, 2026
@dan-petty
dan-petty marked this pull request as ready for review November 21, 2026 03:31
@dan-petty
dan-petty merged commit b2a277b into main Nov 21, 2026
27 checks passed
@dan-petty
dan-petty deleted the perf/4668-share-the-listing-snapshot-in-valkey branch November 21, 2026 03:32
dan-petty-release Bot added a commit that referenced this pull request Nov 21, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.187.0](v0.186.0...v0.187.0)
(2026-11-21)


### Features

* **roadmap:** read project review facts through a catalog
([#6586](#6586))
([752c6ed](752c6ed))


### Bug Fixes

* **ci:** the fail-to-pass replay clears the addopts
([#6593](#6593))
([8bc7afc](8bc7afc)),
closes [#5599](#5599)


### Performance Improvements

* **roadmap:** share the listing snapshot and facts in Valkey
([#6583](#6583))
([b2a277b](b2a277b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
@dan-petty

Copy link
Copy Markdown
Owner Author

Owner decision of 2026-11-21: I accept the visibility cache of 1 hour for the shared listing snapshot.

  • When a repository becomes private, its shared snapshot can stay for up to 1 hour. The visibility cache keeps the last visibility for that time (DEFAULT_BRAIN_VISIBILITY_TTL_SECONDS, 3600 s).
  • A shorter window costs one visibility read for each repository in each round.
  • No change is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/roadmap The roadmap jobs: intake, refine, stage, implement and the Service that runs them type/infra Type infra: the build, CI, images or cluster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(roadmap): share the listing snapshot and tool facts in Valkey

1 participant